package com.googlecode.vijayan.dogen;

/**
 * 
 * @author Vijayan Srinivasan
 * @since Sep 4, 2013 8:16:01 PM
 * 
 */

public class Column {
	private String name;
	private String className;

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getClassName() {
		return this.className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getAttributeName() {
		String temp = this.name.toLowerCase();
		StringBuffer attrName = new StringBuffer();
		char prevChar = ' ';

		for (int i = 0; i < temp.length(); ++i) {
			char c = temp.charAt(i);
			if (prevChar == '_') {
				c = Character.toUpperCase(c);
			}
			if (c != '_') {
				attrName.append(c);
			}
			prevChar = c;
		}

		if (Constants.KEYWORDS.contains(attrName.toString())) {
			attrName.append("_");
		}
		return attrName.toString();
	}

	public String getMethodName() {
		String temp = this.name.toLowerCase();
		StringBuffer methodName = new StringBuffer();
		char prevChar = ' ';

		for (int i = 0; i < temp.length(); ++i) {
			char c = temp.charAt(i);
			if ((i == 0) || (prevChar == '_')) {
				c = Character.toUpperCase(c);
			}
			if (c != '_') {
				methodName.append(c);
			}
			prevChar = c;
		}

		return methodName.toString();
	}

	public String getFriendlyClassName() {
		if (this.className.startsWith("java.lang.")) {
			this.className = this.className.substring("java.lang.".length());
		} else {
			if ("java.sql.Timestamp".equals(this.className)
					|| "java.sql.Date".equals(this.className)
					|| "oracle.sql.TIMESTAMP".equals(this.className))
				return "java.util.Date";
			if ("java.math.BigDecimal".equals(this.className))
				return "Long";
		}
		return this.className;
	}
}
